<!DOCTYPE HTML>
<html>
<head>
    <title>确认户籍迁移</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <script src="/webjars/miniui/boot.js" type="text/javascript"></script>
    <link href="/static/css/resource.css" rel="stylesheet" type="text/css" />
    <link href="/static/css/default.css" rel="stylesheet" type="text/css" />
    <script src="/static/js/common/common.js" type="text/javascript"></script>
</head>
<style>
    .hideBorder {
        border:solid 0px;
    }
</style>

<body onload="onLoad()">
<div class="mini-fit" style="margin-bottom: 40px">
    <div style="height:100%;width: 100%;overflow-x: auto;overflow-y: auto;">
        <form id="form1" method="post" style="margin-top: 10px;">
            <div id="editform" class="form">
                <table class="form-table">
                    <#if !priNum?? >
                        <tr>
                            <td width="150" align="right"><font color="#dc143c">*</font>姓&emsp;&emsp;名:</td>
                            <td style="width: 200px">
                                <div property="editor" id="queryName" class="mini-autocomplete" required="true" style="width:490px;" valueField="id"
                                     textField="name"
                                     url="/azbj/transfer/fqqy/getPrisonerList" showColumns="false" onvaluechanged="getQueryName()"
                                     popupEmptyText="未查询到值......">
                                    <div property="columns">
                                        <div field="name" width="120px"></div>
                                        <div field="danwei" width="180px"></div>
                                        <div field="riqi" width="180px"></div>
                                    </div>
                                </div>
                            </td>
                        </tr>
                    </#if>
                    <#if priNum?? >
                        <tr>
                            <td width="150" align="right"><font color="#dc143c">*</font>姓&emsp;&emsp;名:</td>
                            <td style="width: 200px">
                                <div property="editor" id="queryName" class="mini-autocomplete" required="true" style="width:490px;" valueField="id"
                                     textField="name" enabled='false'
                                     url="/azbj/transfer/fqqy/getPrisonerList" showColumns="false" onvaluechanged="getQueryName()"
                                     popupEmptyText="未查询到值......">
                                    <div property="columns">
                                        <div field="name" width="120px"></div>
                                        <div field="danwei" width="180px"></div>
                                        <div field="riqi" width="180px"></div>
                                    </div>
                                </div>
                            </td>
                        </tr>
                    </#if>
                </table>
            </div>
        </form>
        <form id="form2" method="post">
            <div id="editform" class="form">
                <#--罪犯编号-->
                <input id="priNumNew" name="priNumNew" class="mini-hidden" />
                <table>
                    <tr>
                        <td width="150" align="right"><span style="color: #8B8B8B">姓&emsp;&emsp;名:</span></td>
                        <td>
                            <input id="name" name="name" class="mini-textbox" borderStyle="border:0;" style="width: 500px;" readonly />
                        </td>
                    </tr>
                    <tr>
                        <td width="150" align="right"><span style="color: #8B8B8B">性&emsp;&emsp;别:</span></td>
                        <td>
                            <input id="sex" name="sex" class="mini-textbox" borderStyle="border:0" style="width: 500px;color: #8B8B8B" readonly />
                        </td>
                    </tr>
                    <tr>
                        <td width="150" align="right"><span style="color: #8B8B8B">身份证号:</span></td>
                        <td>
                            <input id="idnum" name="idnum" class="mini-textbox" borderStyle="border:0" style="width: 500px;color: #8B8B8B" readonly />
                        </td>
                    </tr>
                    <tr>
                        <td width="150" align="right"><span style="color: #8B8B8B">出生日期:</span></td>
                        <td>
                            <input id="age" name="age" class="mini-textbox" borderStyle="border:0" style="width: 500px;color: #8B8B8B" readonly />
                        </td>
                    </tr>
                    <tr>
                        <td width="150" align="right"><span style="color: #8B8B8B">户籍地址:</span></td>
                        <td>
                            <input id="hujidi" name="hujidi" class="mini-textbox" borderStyle="border:0" style="width: 500px;color: #8B8B8B"
                                   readonly />
                        </td>
                    </tr>
                    <tr>
                        <td width="150" align="right"><span style="color: #8B8B8B">居住地址:</span></td>
                        <td>
                            <input id="juzhudi" name="juzhudi" class="mini-textbox" borderStyle="border:0" style="width: 500px;color: #8B8B8B"
                                   readonly />
                        </td>
                    </tr>
                </table>
            </div>
        </form>
        <form id="form3" method="post">
            <div id="editform" class="form">
                <#--罪犯编号-->
                <input id="priNum" name="priNum" value="${priNum!''}" class="mini-hidden" />
                <#--id-->
                <input id="id" name="id" value="${id!''}" class="mini-hidden" />
                <#--nativeInvill-->
                <input id="oldnativeinvill" name="oldnativeinvill" value="${nativeInvill!''}" class="mini-hidden" />
                <#--state-->
                <input id="state" name="state" value="${state!''}" class="mini-hidden" />
                <table class="form-table" align="center" style="margin-left: 0px;" cellspacing="5">
                    <tr>
                        <td width="150" align="right"><font color="#dc143c">*</font>任务类型:</td>
                        <td class="input" class="showcell">
                            <input name="taskType" id="taskType" class="mini-combobox" enabled="false"
                                   data="[{ id: 1, name: '单位流转' },{ id: 2, name: '户籍更改' }]"
                                   textField="name" valueField="id" value="${taskType!''}" readonly />
                        </td>
                    </tr>
                    <#if taskType == "2">
                        <tr>
                            <td width="150" align="right"><font color="#dc143c">*</font>地址选择:</td>
                            <td colspan="3">
                                <input id="nativeinpro" name="nativeinpro" class="mini-combobox" required="true"
                                       emptyText="省份" style="width:24%;" enabled="false"
                                       textfield="codeName" valueField="codeId"
                                       url="/azbj/bjdxInfo/getDepart?codeType=2_1&codeId=-1" value="${nativeInpro!''}"
                                       onclick="onDeptChanged('nativeinpro')"
                                       onvaluechanged="onValueChanged('nativeinpro')" readonly />

                                <input id="nativeincity" name="nativeincity" class="mini-combobox" required="true"
                                       emptyText="市" style="width:24%;" enabled="false"
                                       textfield="codeName" valueField="codeId" onclick="onDeptChanged('nativeincity')"
                                       value="${nativeIncity!''}"
                                       onvaluechanged="onValueChanged('nativeincity')"
                                       url="/azbj/bjdxInfo/getDepart?codeType=2_1&codeId=${nativeInpro!''}" readonly />

                                <input id="nativeincou" name="nativeincou" class="mini-combobox" required="true"
                                       emptyText="县" style="width:24%;" enabled="false"
                                       textfield="codeName" valueField="codeId" onclick="onDeptChanged('nativeincou')"
                                       value="${nativeIncou!''}"
                                       onvaluechanged="onValueChanged('nativeincou')"
                                       url="/azbj/bjdxInfo/getDepart?codeType=2_1&codeId=${nativeIncity!''}" readonly />
                                <input id="nativeinvill" name="nativeinvill" class="mini-combobox" required="true"
                                       emptyText="街道" style="width:24%;" enabled="false"
                                       url="/azbj/bjdxInfo/getStreet?parent_code=${nativeIncou!''}"
                                       textfield="name" valueField="code" onclick="onDeptChanged('nativeinvill')"
                                       value="${nativeInvill!''}" readonly />
                            </td>
                        <tr>
                            <td width="150" align="right"></td>
                            <td style="width: 200px">
                                <input class="mini-textbox" style="width: 490px" emptyText="详细地址" id="nativeinnum" enabled="false"
                                       name="nativeinnum" value="${nativeInnum!''}" required="true" readonly />
                            </td>
                        </tr>
                        </tr>
                    </#if>
                    <#if taskType == "1">
                        <tr>
                            <td width="150" align="right"><font color="#dc143c">*</font>转至省份:</td>
                            <td style="width: 350px">
                                <input id="nativepro" name="nativepro" class="mini-combobox" required="true"
                                       emptyText="省份" enabled="false"
                                       textField="codeName" valueField="codeId"
                                       url="/azbj/bjdxInfo/getDepart?codeType=2_1&codeId=-1" value="${nativepro!''}"
                                       onclick="onDeptChanged('nativepro')"
                                       onvaluechanged="onValueChanged('nativepro')" readonly />
                                <input name="prisonUnit" id="prisonUnit" class="mini-combobox" enabled="false"
                                       data="[{ id: '01', name: '监狱' }]"
                                       textField="name" valueField="id" value="${prisonUnit!''}" required="true"
                                       emptyText="服刑单位" readonly />
                                <input id="zpdanwei" name="zpdanwei" class="mini-combobox" required="true"
                                       emptyText="单位名称" enabled="false"
                                       textField="name" valueField="id" onclick="onDeptChanged('zpdanwei')"
                                       value="${zpdanwei!''}"
                                       onvaluechanged="onValueChanged('zpdanwei')"
                                       url="/azbj/transfer/fqqy/getDepartmentById?id=${zpdanwei!''}" readonly />
                            </td>
                        </tr>
                    </#if>
                    <tr>
                        <td width="150" align="right"><font color="#dc143c">*</font>联&ensp;系&ensp;人:</td>
                        <td style="width: 200px">
                            <input id="qclxr" name="qclxr" class="mini-textbox" style="width: 490px;" value="${qclxr!''}" enabled="false"
                                   required="true" readonly />
                        </td>
                    </tr>
                    <tr>
                        <td width="150" align="right">发起迁移人员手机号码:</td>
                        <td style="width: 200px">
                            <input id="qclxdh" name="qclxdh" class="mini-textbox" style="width: 490px;" value="${qclxdh!''}" enabled="false"
                                   readonly />
                        </td>
                    </tr>
                    <tr>
                        <td width="150" align="right">发起迁移人员固话:</td>
                        <td>
                            <input id="fixedLine" name="fixedLine" class="mini-textbox" style="width: 490px;" value="${qclxgh!''}" enabled="false"
                                   readonly />
                        </td>
                    </tr>
                    <tr>
                        <td width="150" align="right"><font color="#dc143c">*</font>备&emsp;&emsp;注:</td>
                        <td>
                            <input id="remark" name="remark" class="mini-textarea" style="width: 490px;" value="${remark!''}" required="true"
                                   enabled="false" readonly />
                        </td>
                    </tr>
                    <tr>
                        <td width="150" align="right"><font color="#dc143c">*</font>申请时间:</td>
                        <td style="width: 200px">
                            <input id="moveOutTime" name="moveOutTime" allowInput="true" class="mini-datepicker" value="${moveOutTime!''}"
                                   style="width: 200px" required="true"
                                   nullValue="null" format="yyyy-MM-dd" showTime="true"
                                   showOkButton="true" enabled="false" showClearButton="false" readonly />
                        </td>
                    </tr>
                    <tr>
                        <td width="150" align="right"><font color="#dc143c">*</font>备注信息:</td>
                        <td>
                            <input id="qrdRemark" name="qrdRemark" class="mini-textarea" style="width: 490px;" value="${qrdRemark!''}"
                                   required="true" />
                        </td>
                    </tr>
                </table>
            </div>
        </form>
        <form id="form5" method="post">
            <div>
                <table class="form-table" align="center">
                    <tr>
                        <td><font color="#dc143c">*</font>审核人员:</td>
                        <td class="input">
                            <input name="qrlxr" id="qrlxr" value="${qrlxr!''}"
                                   style="width: 120px" class="mini-textbox" required="true" />
                        </td>
                        <td>审核人员手机号码:</td>
                        <td class="input">
                            <input name="qrlxdh" id="qrlxdh" value="${qrlxdh!''}" emptyText="请输入手机号码"
                                   onvaluechanged="checkPhone(2)" style="width: 110px" class="mini-textbox" required="false" />
                        </td>
                        <td>审核人员固话:</td>
                        <td class="input">
                            <input name="qrlxgh" id="qrlxgh" value="${qrlxgh!''}" emptyText="请输入固定电话"
                                   onvaluechanged="checkPhone(1)" style="width: 110px" class="mini-textbox" required="false" />
                        </td>
                    </tr>
                    <tr></tr>
                </table>
            </div>
        </form>
        <form id="form4" method="post">
            <!-- 用户 编辑框START-->
            <div id="fileform" class="form">
                <table id="fjscTb" class="form-table">
                    <td class="input">
                        <input type="button" onclick="onFileUpload()" value="查看附件" style="width: 100px" />
                    </td>
                </table>
            </div>
        </form>
    </div>
</div>
<div style="position: absolute;bottom: 0;line-height:40px;width: 100%;border-top: 1px solid #dfdfdf;text-align: center">
    <a class="mini-button" iconCls="fa-undo" plain="true" onclick="close('cancel')">取消</a>
    <a class="mini-button" iconCls="fa-save" plain="true" onclick="saveData(3)">拒绝</a>
    <a class="mini-button" iconCls="fa-save" plain="true" onclick="saveData(2)">同意</a>
</div>

<script type="text/javascript">
    mini.parse();
    var form1 = new mini.Form("form1");
    var form2 = new mini.Form("form2");
    var form3 = new mini.Form("form3");
    var form5 = new mini.Form("form5");
    var queryNameObj = mini.get("queryName");
    var priNumObj = mini.get("priNum");
    var idObj = mini.get("id");
    var nativeinpro = mini.get("nativeinpro");
    var nativeincity = mini.get("nativeincity");
    var nativeincou = mini.get("nativeincou");
    var nativeinvill = mini.get("nativeinvill");
    var oldnativeinvill = mini.get("oldnativeinvill");
    var state = mini.get("state");
    var nativenum = mini.get("nativenum");
    var phone = mini.get("qclxdh");
    var telPhone = mini.get("fixedLine");
    var nativepro = mini.get("nativepro");
    var nativecity = mini.get("nativecity");
    var nativecou = mini.get("nativecou");
    var nativevill = mini.get("nativevill");
    var prisonUnit = mini.get("prisonUnit");
    var zpdanwei = mini.get("zpdanwei");
    var taskType = mini.get("taskType");
    var phone = mini.get("qrlxdh");
    var telPhone = mini.get("qrlxgh");
    var qrlxr = mini.get("qrlxr");

    function onLoad() {
        var priNum = priNumObj.getValue();
        getQueryName(priNum);
        setZpdanwei(${zpdanwei});
    }

    function setZpdanwei(data) {
        // 根据ID去数据库中查询数据
        $.ajax({
            url: "/azbj/transfer/fqqy/getDepartmentById?id=" + data,
            type: "GET",
            dataType: "json",
            success: function (bsdata) {
                var bf = mini.decode(bsdata);
                zpdanwei.setData([{id: bf.id, name: bf.name}]);
            }
        })
    }

    function checkPhone(e) {
        var phone = mini.get("qrlxdh").getValue();
        var telPhone = mini.get("qrlxgh").getValue();
        if (e == '1') {
            if (!validateTel(telPhone)) {
                mini.alert("固定电话有误，请重填");
            }
        }
        if (e == '2') {
            if (!validatePhone1(phone)) {
                mini.alert("手机号码有误，请重填");
            }
        }
    }

    function saveData(e) {
        form3.validate();
        form5.validate();
        if (form3.isValid() == false) {
            return;
        }
        if (form5.isValid() == false) {
            return;
        }
        var data = form3.getData();
        //校验电话与固话必须输入一个
        var phone = mini.get("qrlxdh").getValue();
        var telPhone = mini.get("qrlxgh").getValue();
        var newPhone = checkTelAndPhone(telPhone, phone);
        var flag = newPhone['flag'];
        var kflag = newPhone['kflag'];
        if ('-1' === kflag) {
            mini.alert("请至少输入一个联系方式");
            return;
        }
        if (flag) {
        } else {
            mini.alert("手机号码或固话有误，请重填");
            return;
        }
        // 校验审核人员
        if (qrlxr.getValue() == "") {
            mini.alert("请输入审核人员名称");
            return;
        }
        var priNum = queryNameObj.getValue();
        var priNum1 = priNumObj.getValue();
        if (priNum1) {
            priNum = priNum1;
        }
        if (!priNum) {
            mini.alert("请填写迁移人员");
            return;
        }
        if (taskType.getValue() == '2') {
            var nativeinproName = nativeinpro.getText();
            var nativeincityName = nativeincity.getText();
            var nativeincouName = nativeincou.getText();
            var nativeinvillName = nativeinvill.getText();
            data.nativeInproName = nativeinproName;
            data.nativeIncityName = nativeincityName;
            data.nativeIncouName = nativeincouName;
            data.nativeInvillName = nativeinvillName;
        } else if (taskType.getValue() == '1') {
            var zpdanweiName = zpdanwei.getText();
            var proName = nativepro.getText();
            var unit = prisonUnit.getValue();
            data.zpdanweiName = zpdanweiName;
            data.nativeproName = proName;
            if (unit == '05') {
                var cityName = nativecity.getText();
                var couName = nativecou.getText();
                var villName = nativevill.getText();
                data.nativecityName = cityName;
                data.nativecouName = couName;
                data.nativevillName = villName;
            }
            data.prisonUnit = unit;
            data.nativecityName = "";
            data.nativecouName = "";
            data.nativevillName = "";

        }
        data.priNum = priNum;
        data.state = e;
        data.qrlxdh = phone;
        data.qrlxgh = telPhone;
        data.qrlxr = qrlxr.getValue();
        var json = mini.encode(data);
        $.ajax({
            url: "/azbj/transfer/fqqy/savePrisonerTransfer",
            type: "post",
            data: {data: json},
            success: function (success) {
                if (success.code == 4000) {
                    mini.alert("保存失败");
                } else if (success.code == 1) {
                    mini.alert("保存成功", "成功", window.CloseOwnerWindow);
                } else if (success.code == 5599) {
                    mini.alert(success.message);
                } else {
                    mini.alert(success.message);
                }
            }
        });
    }

    function getQueryName(priNum) {
        if (!priNum) {
            priNum = queryNameObj.getValue();
        }
        if (!priNum) {
            return;
        }
        $.ajax({
            url: "/azbj/transfer/fqqy/getBaseInfoByPriNumMap?priNum=" + priNum,
            type: "post",
            success: function (result) {
                if (result.data != null) {
                    var info = result.data;
                    var data = {};
                    data.name = info.pName;
                    if (info.sex == 0) {
                        data.sex = "未知的性别";
                    } else if (info.sex == 1) {
                        data.sex = "男性";
                    } else if (info.sex == 2) {
                        data.sex = "女性";
                    } else {
                        data.sex = "未说明的性别";
                    }
                    data.idnum = info.idNum;
                    data.age = info.age;
                    var hujidi = "";
                    if (info.nativeproName) {
                        hujidi += info.nativeproName;
                    }
                    if (info.nativecityName) {
                        hujidi += info.nativecityName;
                    }
                    if (info.nativecouName) {
                        hujidi += info.nativecouName;
                    }
                    if (info.nativevillName) {
                        hujidi += info.nativevillName;
                    }
                    if (info.nativenum) {
                        hujidi += info.nativenum;
                    }
                    data.hujidi = hujidi;
                    var juzhudi = "";
                    if (info.placeproName) {
                        juzhudi += info.placeproName;
                    }
                    if (info.placecityName) {
                        juzhudi += info.placecityName;
                    }
                    if (info.placecouName) {
                        juzhudi += info.placecouName;
                    }
                    if (info.placevillName) {
                        juzhudi += info.placevillName;
                    }
                    if (info.placenum) {
                        juzhudi += info.placenum;
                    }
                    data.juzhudi = juzhudi;
                    data.priNumNew = info.priNum;
                    form2.setData(data);
                    queryNameObj.setText(info.pName);
                    onDeptChanged('nativeinvill');
                }
            }
        });
    }

    /**
     * 迁移地址
     * @param e
     */
    var urltemp = "/azbj/bjdxInfo/getDepart?codeType=2_1&codeId=-100";

    function onDeptChanged(e) {
        // nativeinpro nativeincity  nativeincou nativeinvill
        if ("nativeinpro" == e) {
            var value = nativeinpro.getValue();
            nativeinpro.setValue("");
            var url = "/azbj/bjdxInfo/getDepart?codeType=2_1&codeId=-1";
            nativeinpro.setUrl(url);
            if (value != '') {
                nativeinpro.setValue(value);
            } else {
                nativeinpro.select(0);
            }
        }
        if ("nativeincity" == e) {
            var value = nativeincity.getValue();

            if (nativeinpro.getValue() == "") {
                nativeincity.setUrl(urltemp);
                nativeincity.setValue("");
                nativeincou.setUrl(urltemp);
                nativeincou.setValue("");
                nativeinvill.setUrl(urltemp);
                nativeinvill.setValue("");
                return;
            }
            var codeId = nativeinpro.getValue();
            nativeincity.setValue("");
            var url = "/azbj/bjdxInfo/getDepart?codeType=2_1&codeId=" + codeId;
            nativeincity.setUrl(url);
            if (value != '') {
                nativeincity.setValue(value);
            } else {
                nativeincity.select(0);
            }
        }
        if ("nativeincou" == e) {
            var value = nativeincou.getValue();

            if (nativeincity.getValue() == "") {
                nativeincou.setUrl(urltemp);
                nativeincou.setValue("");
                nativeinvill.setUrl(urltemp);
                nativeinvill.setValue("");
                return;
            }
            var codeId = nativeincity.getValue();
            nativeincou.setValue("");
            var url = "/azbj/bjdxInfo/getDepart?codeType=2_1&codeId=" + codeId;
            nativeincou.setUrl(url);
            if (value != '') {
                nativeincou.setValue(value);
            } else {
                nativeincou.select(0);
            }
        }
        if ("nativeinvill" == e) {
            var value = nativeinvill.getValue();

            if (nativeincou.getValue() == "") {
                nativeinvill.setUrl(urltemp);
                nativeinvill.setValue("");
                return;
            }
            var parent_code = nativeincou.getValue();
            nativeinvill.setValue("");
            var url = "/azbj/bjdxInfo/getQcStreet?parentCode=" + parent_code + "&priNum=" + mini.get("priNumNew").getValue();
            nativeinvill.setUrl(url);
            if (value != '') {
                nativeinvill.setValue(value);
            } else {
                nativeinvill.select(0);
            }
        }
    }

    function onValueChanged(e) {
        if ("nativeinpro" == e) {
            nativeincity.setValue("");
            nativeincou.setValue("");
            nativeinvill.setValue("");
        }
        if ("nativeincity" == e) {
            nativeincou.setValue("");
            nativeinvill.setValue("");
        }
        if ("nativeincou" == e) {
            nativeinvill.setValue("");
        }
    }

    function close(action) {
        if (window.CloseOwnerWindow) {
            window.CloseOwnerWindow(action);
        } else {
            window.close();
        }
    }

    // 上传附件
    function onFileUpload() {//taskId为33是户籍迁移附件
        var nouploadflag = "5000";
        commonEdit("/upload/user/uploadAppendixfile/noupload/view?1=1&id=${id!''}&priNum=${priNum!''}&taskId=33&nouploadflag=" + nouploadflag, null, null, 600, 400, true, true, true);
    }
</script>
</body>
</html>